The Memory Manager compacts and purges the heap whenever necessary to satisfy requests for memory. You can also compact or purge the heap manually. To compact the current heap zone manually, use the CompactMem function. To purge it manually, use the PurgeMem procedure. To do both at once, use the MaxMem function. To perform the same operations on the system heap zone, use the CompactMemSys function, the PurgeMemSys procedure, and the MaxMemSys function.
Most applications don't need to call the routines described in this section. Normally you should let the Memory Manager compact or purge your application heap.
The Memory Manager compacts the heap for you when you make a memory request that it can't fill. However, you can use the CompactMem function to compact the current heap zone manually.
FUNCTION CompactMem (cbNeeded: Size): Size;
The CompactMem function compacts the current heap zone by moving unlocked, relocatable blocks down until they encounter nonrelocatable blocks or locked, relocatable blocks, but not by purging blocks. It continues compacting until it either finds a contiguous block of at least cbNeeded free bytes or has compacted the entire zone.
The CompactMem function returns the size, in bytes, of the largest contiguous free block for which it could make room, but it does not actually allocate that block.
To compact the entire heap zone, call CompactMem(maxSize) . The Memory Manager defines the constant maxSize for the largest contiguous block possible in the 24-bit Memory Manager:
CONST
maxSize = $800000; {maximum size of a block}
The registers on entry and exit for CompactMem are
Registers on exit |
|
---|---|
The CompactMem function compacts the current heap zone. If you want to compact the system heap zone rather than the current heap zone, set bit 10 of the routine trap word. In most development systems, you can do this by supplying the word SYS as the second argument to the routine macro, as follows:
_CompactMem ,SYS
You can use the CompactMemSys function to compact the system heap zone manually.
FUNCTION CompactMemSys (cbNeeded: Size): Size;
The Memory Manager purges the heap for you when you make a memory request that it can't fill. However, you can use the PurgeMem procedure to purge the current heap zone manually.
PROCEDURE PurgeMem (cbNeeded: Size);
The PurgeMem procedure sequentially purges blocks from the current heap zone until it either allocates a contiguous block of at least cbNeeded free bytes or has purged the entire zone. If it purges the entire zone without creating a contiguous block of at least cbNeeded free bytes, PurgeMem generates a memFullErr .
The PurgeMem procedure purges only relocatable, unlocked, purgeable blocks.
The PurgeMem procedure does not actually attempt to allocate a block of cbNeeded bytes.
The registers on entry and exit for PurgeMem are
Registers on exit |
|
---|---|
The PurgeMem procedure purges the current heap zone. If you want to purge the system heap zone rather than the current heap zone, set bit 10 of the routine trap word. In most development systems, you can do this by supplying the word SYS as the second argument to the routine macro, as follows:
_PurgeMem ,SYS
You can use the PurgeMemSys procedure to purge the system heap manually.
PROCEDURE PurgeMemSys (cbNeeded: Size);
Use the MaxMem function to compact and purge the current heap zone.
FUNCTION MaxMem (VAR grow: Size): Size;
The MaxMem function compacts the current heap zone and purges all relocatable, unlocked, and purgeable blocks from the zone. It returns the size, in bytes, of the largest contiguous free block in the zone after the compacting and purging. If the current zone is the original application zone, the grow parameter is set to the maximum number of bytes by which the zone can grow. For any other heap zone, grow is set to 0. MaxMem doesn't actually expand the zone or call the zone's grow-zone function.
Because MaxMem moves and purges memory, you should not call it at interrupt time.
The registers on exit for MaxMem are
The MaxMem function compacts the current heap zone. If you want to compact and purge the system heap zone rather than the current heap zone, set bit 10 of the routine trap word. In most development systems, you can do this by supplying the word SYS as the second argument to the routine macro, as follows:
_MaxMem ,SYS
You can use the MaxMemSys function to purge and compact the system heap zone manually.
FUNCTION MaxMemSys (VAR grow: Size): Size;